<?php
namespace Admin\Controller;
use Think\Controller;
class BookController extends Controller {
     public function bookfenlei(){    
        $this->display();   
    }
     public function fenlei(){
     	if($_POST['typename']) {
        $typename = $_POST['typename'];
        $type=M('fenlei');
        $data=array('booktype'=>$typename);
        $fenlei=$type->add($data);
        }
        
        if($fenlei) {
            $this->success('添加书籍分类成功','bookfenlei');
        } else {
            $this->error('添加书籍分类失败，请重新填写','bookfenlei');
        }
       
    }
     
     public function addbook(){
     	$all=M('fenlei')->select();
		$this->assign('tt',$all);
        $this->display();   
    }
     public function addbook1(){
    
        // $upload=new \Think\Upload();
        // $upload->exts= array('jpg', 'gif', 'png', 'jpeg');
        // $upload->rootPath  = './Public/Uploads/images/'; // 设置附件上传根目录
        // $info = $upload -> upload();
            
        // if (!$info){  
        //     $this->error($upload->getError());  
        // }else{  
               
        //     foreach($info as $file){
        //     $file_path="./Public/Uploads/images/".$file['savepath'].$file['savename'];
        //     $image = new \Think\Image();
        //     $image->open($file_path);
        //     $image->thumb(120, 120)->save($file_path);
        //     }
               
        // } 
        $suotu=$_POST['suotu'];
		$id=$_POST['sel'];        
		$ctime = $_POST['ctime'];
        $rl = $_POST['rl'];
        $sn = $_POST['sn']; 
        $sid=$id;		
        $title=$_POST['title'];      
        $keyword=$_POST['keyword'];
        $note=$_POST['note'];
        $writer=$_POST['writer'];
        $laiyuan=$_POST['laiyuan'];
        $content=$_POST['content']; 
        $price=$_POST['price'];
        $yeshu = $_POST['yeshu'];
        $weizhi = $_POST['weizhi'];
        $guige = $_POST['guige'];
        $number=$_POST['number'];
        $time=time();
        $date=date("Y-m-d H:i:d",$time);
        $data=array('title'=>$title,'note'=>$note,'keyword'=>$keyword,'writer'=>$writer,
            'laiyuan'=>$laiyuan,'suotu'=>$suotu,'content'=>$content,
              'isbn'=>$sn,'chubantime'=>$ctime,
            'yeshu'=>$yeshu,'place'=>$weizhi,'bookurl'=>$rl,
            'price'=>$price,'number'=>$number,'addtime'=>$date,'sid'=>$sid,'guige'=>$guige);
        $adbook=M('addbook')->add($data);
    if($adbook) {       
        $this->success('录入书籍信息成功','addbook');
    } else {
        $this->error('录入书籍信息失败,请填写完整','addbook');
    }

}
        Public function allbook(){
            $book = M('addbook')->select();
            $this->assign('book',$book);
            $this->display();
        }     


        public function xiugaibook() {
               $bookid = $_GET['id'];
               $all=M('fenlei')->select();
               $this->assign('tt',$all);
               $data['id'] = $bookid;
               $book = M('addbook')->where($data)->select(); 
               $this->assign('book',$book); 
               $this->assign('bookid',$book['0']['id']);
               $this->display(); 
        }

        public function xiugai() {
            $bookid = $_GET['id'];


        
        $id=$_POST['sel'];        
        $ctime = $_POST['ctime'];
        
        $sn = $_POST['sn']; 
        $sid=$id;       
        $title=$_POST['title'];      
        $keyword=$_POST['keyword'];
        $note=$_POST['note'];
        $writer=$_POST['writer'];
        $laiyuan=$_POST['laiyuan'];
        $content=$_POST['content']; 
        $price=$_POST['price'];
        $yeshu = $_POST['yeshu'];
        $weizhi = $_POST['weizhi'];
        $guige = $_POST['guige'];
        $number=$_POST['number'];
        $time=time();
        $date=date("Y-m-d H:i:d",$time);
        $data=array('title'=>$title,'note'=>$note,'keyword'=>$keyword,'writer'=>$writer,
            'laiyuan'=>$laiyuan,'content'=>$content,
              'isbn'=>$sn,'chubantime'=>$ctime,
            'yeshu'=>$yeshu,'place'=>$weizhi,
            'price'=>$price,'number'=>$number,'addtime'=>$date,'sid'=>$sid,'guige'=>$guige);
         $da['id'] = $bookid;
        $adbook=M('addbook')->where($da)->save($data);
    if($adbook) {       
        $this->success('修改书籍信息成功',U('Book/allbook'));
    } else {
        $this->error('修改书籍信息失败,请重新修改');
    }
        }



        public function dlebook() {
            $bookid = $_GET['id'];
            $data['id'] = $bookid;
            $info = M('addbook')->where($data)->delete(); 
            if($info){
                $this->success('删除图书成功',U('Book/allbook'));
            } else {
                $this->error('删除图书失败，请重新删除');
            }
        }

        public function ssbook() {
            $this->display();
        }

        Public function ssjieguo() {
         $keyword = $_POST['guanjianzi'];                         
         if($keyword){
            $data['isbn|keyword|title|writer|id|place'] = array('like',"%$keyword%");
         $book = M('addbook')->where($data)->select();
        }

        if(empty($book)){
            $info = '没有搜索结果,请重新搜索V_V';
         }
          $this->assign('info',$info);
         $this->assign('book',$book);
         $this->display();
}
		
		public function flchakan(){
			 $fenlei = M('fenlei')->select();
			 $this->assign('fenlei',$fenlei);  
			 $this->display();
		}
		
		public function flbook() {
			$fenleiid = $_GET['id'];
			$date['id'] = $fenleiid;
			$fenlei = M('fenlei')->where($date)->find();
			$this->assign('fenlei',$fenlei['booktype']);
			$data['sid'] = $fenleiid;
			$book = M('addbook')->where($data)->select();
			$this->assign('book',$book);
			$this->display();
		}
		
		public function weihuanbook(){
			$data['zhuangtai'] = 1;
			$bookid = M('jieshu')->where($data)->field('bookid,userid')->find();
			
			$date['id'] = array(in,$bookid);
			$book = M('addbook')->where($date)->select();
			var_dump($book);
		}
      
}